import type {
  FinalDefenseAddDTOType,
  FinalDefenseSearchDTOType,
  FinalDefenseSearchVOType,
  FinalDefenseUpdateDTOType
} from '@/resources/interface/finalDefense/FinalDefenseTypes'
import type { TableColumn } from '@/components/CommonTable.vue'
import { ComponentEnum, type FormItemConfig } from '@/components/CommonDialogForm.vue'
import type {
  MidtermDefenseAddDTOType
} from '@/resources/interface/midtermDefense/MidtermDefenseTypes.ts'
import { markRaw } from 'vue'
import {
  ElButton,
  ElDatePicker,
  ElNotification,
  type UploadFile,
  type UploadFiles
} from 'element-plus'
import { FileApi } from '@/apis/api/file/FileApi.ts'
import type { ResultTypes } from '@/resources/interface/ResultTypes.ts'
import type {
  ProposalReportSearchVOType
} from '@/resources/interface/proposalReport/ProposalReportTypes.ts'
import { RoleUtils } from '@/utils/RoleUtils.ts'

/**
 * 终期答辩表 参数对象
 */
export class FinalDefenseParams {
  /**
   * 表单参数
   */
  static formColumn: FormItemConfig[] = [
    {
      label: '题目',
      prop: 'projectId',
      type: ComponentEnum.SELECT,
      field: 'projectId',
      options: [],
    },
    {
      label: '答辩时间',
      prop: 'defenseTime',
      type: ComponentEnum.CUSTOMIZE,
      field: 'defenseTime',
      component: markRaw(ElDatePicker),
      attribute: {
        type: 'datetime',
        placeholder: '选择日期',
        valueFormat: 'YYYY-MM-DD hh:mm:ss',
        style: {
          width: '100%',
        },
      },
    },
    {
      label: '答辩材料',
      prop: 'documentPath',
      type: ComponentEnum.UPLOAD,
      field: 'documentPath',
      options: {
        isActor: false,
        action: FileApi.uploadUrl,
        fileList: [],
        method: {
          success: (response: ResultTypes, params: MidtermDefenseAddDTOType) => {
            params.documentPath = response.data
          },
        },
      },
      attribute: {
        'show-file-list': true,
        data: { bucket: 'final' },
        'before-remove': async (uploadFile: UploadFile, uploadFiles: UploadFiles) => {
          const response: ResultTypes = <ResultTypes>uploadFile.response
          if (response) {
            await FileApi.delete(response.data)
          }
        },
      },
    },
  ]
  /**
   * 表格参数
   */
  static tableColumn: TableColumn[] = [
    {
      label: '学生名称',
      field: 'studentName',
    },
    {
      label: '题目名称',
      field: 'projectName',
    },
    {
      label: '答辩时间',
      field: 'defenseTime',
    },
    {
      label: '答辩材料',
      field: 'documentPath',
      formatter(row: ProposalReportSearchVOType) {
        return '查看文件'
      },
      template: {
        component: markRaw(ElButton),
        options: (row: ProposalReportSearchVOType, click: Function) => ({
          type: 'primary',
          link: true,
          style: {
            color: '#409EFF',
          },
          onClick: () => {
            if (row.documentPath) {
              window.open(row.documentPath, '_blank')
            } else {
              ElNotification.error('未上传文件')
            }
          },
        }),
      },
    },
    {
      label: '评审状态',
      field: 'status',
      formatter(row) {
        return row.status === 0 ? '未评审' : row.status === 1 ? '评审通过' : '评审不通过'
      },
    },
    {
      label: '答辩评分',
      field: 'score',
    },
    {
      label: '评审意见',
      field: 'reviewComment',
    },
    {
      label: '评审人员',
      field: 'reviewerName',
    },
    {
      label: '审核时间',
      field: 'reviewTime',
    },
    {
      label: '操作',
      field: 'right',
      attribute: {
        fixed: 'right',
        width: '200px',
      },
      template: {
        options: [
          {
            type: 'success',
            size: 'small',
            method: 'audit',
            label: '审核',
            show: (params: ProposalReportSearchVOType) =>
              RoleUtils.verifyRole([1, 3]) && params.status == 0,
          },
          {
            type: 'success',
            size: 'small',
            method: 'detail',
            label: '查看',
          },
        ],
      },
    },
  ]
  /**
   * 添加对象
   */
  static addDTO: FinalDefenseAddDTOType = {
    projectId: '',
    defenseTime: '',
    documentPath: '',
  }
  /**
   * 修改对象
   */
  static updateDTO: FinalDefenseUpdateDTOType = {
    id: 0,
    studentId: 0,
    projectId: 0,
    defenseTime: '',
    documentPath: '',
    score: 0,
    reviewComment: '',
    status: 0,
    reviewerId: 0,
    reviewTime: '',
  }
  /**
   * 查询对象
   */
  static searchDTO: FinalDefenseSearchDTOType = {
    projectName: '',
    status: 0,
    page: {
      current: 1,
      size: 20,
    },
  }
  static searchVO: FinalDefenseSearchVOType = {
    createBy: '',
    createTime: '',
    defenseTime: '',
    documentPath: '',
    id: 0,
    projectId: 0,
    projectName: '',
    reviewComment: '',
    reviewTime: '',
    reviewerId: 0,
    reviewerName: '',
    score: 0,
    status: 0,
    studentId: 0,
    studentName: '',
    updateBy: '',
    updateTime: '',
  }
}
